
Piece.prototype = new Printer();

function Piece(io_obj, color_str){
	/** HERITAGE */
	this.parent = Printer;
	this.parent (io_obj);

	/** PRIVATE */
	this._type = null;
	this._location = null;
	this._color_str = null;
	this._chessboard = null;
	this._movetype = null;

	/** PUBLIC */
	this.COLOR_WHITE = "white";
	this.COLOR_BLACK = "black";
	this.MOVE_TYPE_LINEAR = 0;
	this.MOVE_TYPE_JUMP = 1;

	this._constructor = function piece__constructor (color_str) {
		// fill with the color
		this._io = io_obj;
		this._color_str = color_str;
	}

	this.getType = function piece_getType () {
		var result;
		result = this._color_str+"_"+this._type;
		// this._io.print("Piece color = "+result);
		return result;
	}

	this.setChessBoard = function piece_setChessBoard (chessboard_obj) {
		this._chessboard = chessboard_obj;
	}

	this.setLocation = function piece_setLocation (loc_obj) {
		// Set the location of the piece on the chessboard		
		this._location = loc_obj;
	}

	this.getLocation = function piece_getLocation (loc_obj) {
		return this._location;
	}

	this.getColor = function piece_getColor (){
		return this._color_str;
	}

	this.isMovable = function piece_isMovable () {
		// Returns wether the piece can move
		return false; // by default
	}


	this.canCollideAt = function piece_canCollideAt (loc_obj) {
		// take if a piece of the opponent's color is found
		var chessboard_obj;
		var result;
		var piece_obj;
		chessboard_obj = this._chessboard;	
		if (chessboard_obj.isPieceAt (loc_obj)){ 
			piece_obj = chessboard_obj.getPieceAt (loc_obj);
			if (piece_obj.getColor() == this.getColor()){
				result = true;
			} else {
				result = false;
			}
		} else {
			result = false;
		}
		return result;
	}

	this.canTakeAt = function piece_canTakeAt (loc_obj) {
		// take if a piece of the opponent's color is found
		var chessboard_obj;
		var result;
		var piece_obj;
		chessboard_obj = this._chessboard;	
		if (chessboard_obj.isPieceAt (loc_obj)){ 
			piece_obj = chessboard_obj.getPieceAt (loc_obj);
			if (piece_obj.getColor() != this.getColor()){
				result = true;
			} else {
				result = false;
			}
		} else {
			result = false;
		}
		return result;
	}
	
	this.canMoveTo = function piece_canMoveTo (loc_obj) {
		// Returns wether the piece can move to the specified location
		return false;	
	}

	/** CONSTRUCT ! */
	this._constructor(color_str);
}
